Skip to content

feat(cli): phase-1 gaps — TOON output, mcp create, monit-query/agent, plural --channel#11

Merged
ysyneu merged 8 commits into
mainfrom
feat/cli-phase1-gaps
May 28, 2026
Merged

feat(cli): phase-1 gaps — TOON output, mcp create, monit-query/agent, plural --channel#11
ysyneu merged 8 commits into
mainfrom
feat/cli-phase1-gaps

Conversation

@ysyneu
Copy link
Copy Markdown
Contributor

@ysyneu ysyneu commented May 27, 2026

Summary

Phase-1 gap-closing for the fc-safari ai-sre agent path (see fc-safari PR #74 for the consumer side). Five additions to the flashduty CLI:

  1. --output-format toon — a token-efficient output mode for the LLM agent.
  2. mcp create — register an MCP server from the CLI.
  3. monit-query diagnose|rows + monit-agent catalog|invoke — datasource-side and on-box diagnostics subcommands the AI-SRE skills drive.
  4. change list --channel — comma-separated IDs (plural), matching alert list.
  5. SDK pin to the dev integration branch (build hygiene).

1. TOON output mode (7da8c5b3)

The agent reads CLI output as tokens. JSON repeats every key on every row of a list; TOON (Token-Oriented Object Notation) emits the key set once and then bare rows, so a 50-incident list costs far fewer tokens. This mirrors how the Flashduty MCP server already exposes TOON.

  • internal/output/format.go — new type Format int { FormatTable, FormatJSON, FormatTOON } with Structured() (true for JSON + TOON).
  • internal/output/toon.goTOONPrinter delegates to flashduty-sdk's Marshal(data, sdk.OutputFormatTOON) (the SDK already vendors toon-go; the CLI is thin wiring, not a new encoder).
  • internal/cli/root.go — new persistent --output-format table|json|toon flag (inherited by every subcommand). --json is kept as an alias for --output-format json. resolveOutputFormat() makes --output-format win, falls back to --json, and errors on an unknown value (validated in PersistentPreRunE). marshalStructured() routes TOON through sdk.Marshal and keeps json.MarshalIndent for the JSON path.
  • internal/cli/command.goRunContext.JSON bool became Format output.Format + a Structured() method; all list/total/result printers switch on it.

JSON output is byte-for-byte unchanged — only TOON is new. Existing --json consumers and pipelines are unaffected.

Tests: internal/cli/output_format_test.go (resolution matrix incl. invalid→error), internal/output/toon_test.go (key-dedup vs row count), and the existing printer tests migrated to the Format API.

2. mcp create (f86006c3, polished in 5cca6fb2)

New command under a new mcp group. Registers an MCP server via flashduty-sdk.CreateMCPServer. 11 flags: --server-name --description --transport --command --args --env --url --headers --connect-timeout --call-timeout --team-id. --env and --headers accept repeatable KEY=VALUE parsed via a new shared parseKVSlice helper (8-case table test: nil / empty / single / multi / value-with-equals / empty-value / empty-key / missing-equals). Validation lives inside the runCommand closure for uniform error rendering; the test exercises the actual RunE path via the saveAndResetGlobals + mockClient fixture.

3. monit-query / monit-agent subcommands (c04b7414, a09fa2c7)

  • flashduty monit-query diagnose|rows — pre-clustered RCA findings and raw passthrough against a backing datasource.
  • flashduty monit-agent catalog|invoke — discover and batch-run on-box diagnostic tools on a target host / mysql instance.

These back the monit-query / monit-agent AI-SRE skills.

4. change list --channel plural (9b542528)

Migrated from singular Int64Var to comma-separated StringVar, routed through the SDK's ListChangesInput.ChannelIDs []int64. Mirrors alert list --channel (already plural) so both commands share filter semantics and match the MCP query_changes.channel_ids schema.

Test plan

  • go test ./... -count=1 green (incl. TOON + resolution tests)
  • make check clean (fmt + lint + test + build)
  • Smoke: bin/flashduty incident list --help shows the inherited --output-format flag
  • Smoke: bin/flashduty mcp create --help shows all 11 flags
  • Smoke: bin/flashduty change list --channel 100,200 --since 1h --output-format toon against a dev account routes through channel_ids
  • Cross-build for linux/amd64: GOOS=linux GOARCH=amd64 make build && file bin/flashduty reports ELF 64-bit ... x86-64 — needed by the fc-safari sandbox image bake

ysyneu added 7 commits May 27, 2026 15:15
Migrate from singular Int64Var to StringVar + parseIntSlice, routing
through ListChangesInput.ChannelIDs []int64 to match the MCP surface
and mirror the existing alert list --channel pattern.
Move --server-name empty-check inside runCommand closure to match the
project convention established in alert.go (validation flows through the
same error formatter as all other business-logic errors).

Rewrite TestMCPCreateRejectsEmptyServerName to use execCommand +
mockClient injection so it survives the guard moving inside runCommand
without depending on real config or network.

Add TestParseKVSlice table-driven tests covering nil/empty/single/multi/
value-with-equals/empty-value/empty-key/missing-equals cases.
Two-step on-box diagnostics surface: `catalog` discovers tools per
target via /monit/tools/catalog, `invoke` runs up to 8 of them
concurrently via /monit/tools/invoke. --tool-spec uses StringArray so
params=<json> bodies with commas survive intact.

Side-fix: extend test-helper resetFlagSet to also clear stringSlice
and stringArray flags between execCommand calls; without it, a later
test sees leftover repeated --flag entries from earlier ones.
CI failures since Phase 1 (commit f86006c) traced to a local-path replace
directive that pointed at /Users/ysy/go/src/github.com/flashcatcloud/
flashduty-sdk — fine for the workstation that authored it, fatal for
GitHub Actions runners that have no such path.

The CLI legitimately depends on unreleased SDK methods (Phase 1's
CreateMCPServer + Phase 2's MonitQuery / MonitAgent). Until both
underlying SDK PRs (#12 mcp-server-create, #13 monit-types) merge and a
v0.10.0 tag ships, we pin to a pseudo-version of the integration branch
flashduty-sdk@dev/sdk-cli-phase2-deps (HEAD 3203385), which merges both
feature branches together. Resolves to:

  v0.9.1-0.20260527160039-3203385df5ad

When SDK v0.10.0 tags, the next commit on this PR just bumps the require
to v0.10.0 and we delete the integration branch — no other CLI code
change needed. The replace directive does not return.
Adds `--output-format table|json|toon` (persistent), with `--json` kept as
an alias for `--output-format json`. TOON (Token-Oriented Object Notation)
drops the per-row repeated keys JSON emits for uniform arrays — materially
fewer tokens for list output, which matters when an LLM agent consumes the
CLI's stdout.

Routes through sdk.Marshal(v, OutputFormatTOON) so the encoding is identical
to the Flashduty MCP server's toon path — one source of truth. The JSON path
is untouched (still indented via json.MarshalIndent), so existing `--json`
consumers get byte-identical output.

Mechanics:
- internal/output: Format enum {Table,JSON,TOON} + Structured() helper;
  NewPrinter takes a Format; new TOONPrinter.
- internal/cli: resolveOutputFormat() (—output-format wins, —json alias,
  unknown value errors via PersistentPreRunE so a typo fails fast);
  marshalStructured() shared by WriteResultJSON / writeResult / whoami;
  RunContext.JSON bool replaced by Format + Structured() — all command
  sites that gated "machine vs human" now honor TOON too.

Tests: TOONPrinter key-dedup vs row count; resolveOutputFormat matrix
incl. invalid→error; existing printer tests migrated to the Format arg.
@ysyneu ysyneu changed the title feat: mcp create + plural --channel; mcp create polish feat(cli): phase-1 gaps — TOON output, mcp create, monit-query/agent, plural --channel May 28, 2026
@ysyneu ysyneu merged commit 39d6bfc into main May 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant